package org.hypheli.testApps;

import org.hh.common.HHObject;
import org.hh.common.KeyPoint;

import com.googlecode.javacv.cpp.opencv_core.IplImage;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;

//import static com.googlecode.javacv.cpp.opencv_core.*;
//import static com.googlecode.javacv.cpp.opencv_imgproc.*;

public class PathPropagation extends HHObject {

	private KeyPoint fCurrPos = null;
	private double fMeterToPix = 0;
	private int fNbOfRay = 4;
	private KeyPoint fCurrTarget = null;
	
	public PathPropagation(String name, double meterToPix) {
		super(name);
		fMeterToPix = meterToPix;
	}
	
	public void setCurrentPosition(KeyPoint currPos){
		fCurrPos = currPos;
	}

	public void onDraw(Canvas canvas, Paint paint){
		if( fCurrPos == null ) return;

		canvas.save();
		
		int xs = (int)(fCurrPos.x * fMeterToPix);
		int ys = (int)(fCurrPos.y * fMeterToPix);
		canvas.translate(xs, ys);
		canvas.rotate(-(float) (fCurrPos.a * 180.0 / Math.PI));
		paint.setARGB(255, 0xAA9900, 0xAA9900, 0xAA9900);

		
		for(int i = 0; i < fNbOfRay; i++){
			float degrees = (float)i * 180.0f/fNbOfRay;
			canvas.save();
			canvas.rotate(degrees, 0, 0);
			canvas.drawLine(-1000, -1000, 1000, 1000, paint);
			canvas.restore();
		}
		canvas.restore();
		
		if( fCurrTarget == null ) return;
		
		
		paint.setARGB(255, 0xFFBBFF, 0, 0);
		canvas.drawLine((float)xs, (float)ys, (float)(fCurrTarget.x*fMeterToPix), (float)(fCurrTarget.y*fMeterToPix), paint);
		
	}
	
	public void onDrawProba(Canvas canvas, Paint paint, IplImage probaImg){
		if( fCurrPos == null ) return;
		
		
		/*
		opencv_imgproc.cvThreshold(fImage, fImage, 70.,//70 is the lower cut off
				150.,// this is the higher cut off
				opencv_imgproc.CV_THRESH_BINARY);
*/

		

	}

	public void onTouch(MotionEvent event){

		float touchX = (int) event.getX();
    float touchY = (int) event.getY();
		
    if( fCurrTarget == null){
    	fCurrTarget = new KeyPoint();
    }
    fCurrTarget.x = touchX / fMeterToPix; // fConvPixToMeter;
    fCurrTarget.y = touchY / fMeterToPix; // fConvPixToMeter;

	}

}
